/*
 *  SimpleOSL.h
 *
 *  Copyright (c) 2003 Satimage. All rights reserved.
 *
 */
#ifndef __SIMPLEOSL__
#define  __SIMPLEOSL__
#include <Carbon/Carbon.h>

#ifdef __cplusplus
extern "C" {
#endif
/* SimpleOSL.h proposes a basic implementation of a scriptable application.
 *
 * The implementation is designed to interface easily computational codes with AppleScript.
 *
 * From AppleScript, you will be controlling your application using:
 * - user-defined application's properties: quantities that you can read/write
 * - user-defined commands.
 *
 * SimpleOSL provides the framework required to handle the "get" and "set" AppleEvents,
 * which are the commands that your script uses to handle the application's properties.
 * Your project should call "InstallOSL()" before running the event loop, and
 * it should implement the four quantities that are declared above:
 * - a routine named "gAEGetProc", that you muse implement as:
 * 	OSErr gAEGetProc(DescType selectedProperty,AEDesc & data){...}
 * 	gAEGetProc must return in "data" the contents of the C variable corresponding
 * 	to the 4-char code "selectedProperty". gAEGetProc will be called each time your
 * 	application receives a "get" AppleEvent.
 * - a routine named "gAESetProc", that you muse implement as:
 * 	OSErr gAESetProc(DescType selectedProperty,AEDesc & data){...}
 * 	gAESetProc must set the C variable which corresponds to the 4-char code "selectedProperty"
 * 	to the value stored in the AEDesc "data". gAESetProc will be called each time your
 * 	application receives a "set" AppleEvent.
 * - an array of DescType (4-char codes) named "gPropertyList", such as:
 * 	DescType gPropertyList[]={'Temp','Pres','Dens','Visc','Velo'};
 * 	This is the list of the properties that your application will return when it
 * 	receives "tell application "YourAppNameHere" to get its properties" - a handy way
 * 	for retrieving the whole set of parameters with one script line.
 * 	gAEGetProc should handle (at least) all the DescType's of gPropertyList.
 * - an integer named "gPropertyListCount" that stores the size of gPropertyList:
 * 	int gPropertyListCount=sizeof(gPropertyList)/sizeof(DescType);
 * 
 * Please note:
 * 1. AEDescUtils provides a set of commands to convert between C variables and AEDesc's.
 * 2. The DescType's that gAEGetProc and gAESetProc handle should be defined in the terminology resource
 * as properties of the "application" class.
 * 
 */

extern DescType gPropertyList[];
extern int gPropertyListCount;
OSErr gAEGetProc(DescType selectedProperty,AEDesc & data);
OSErr gAESetProc(DescType selectedProperty,AEDesc & data);

OSErr InstallOSL();

/*The threaded interface. See ThreadedApp sample code.
 * This interface is provided for lengthy computations or complex interactive debugging.
 * AEInstallThreadedEventHandler installs an AppleEvent handler.
 * This function is equivalent to AEInstallEventHandler, but the EventHandler will execute in a separate thread.
 * This allows monitoring and communications between Smile and your EventHandler.
 * Within your  EventHandler, you can use the function NotifySmile(p,suspend) in order to notify Smile and suspends your EventHandler if "suspend" is true.
 * Smile catches this message if you have defined a "notify" handler in the Smile context.
 *This handler must be declared as:
 *		on notify smile from anApp with data s
 *			...
 *		end
 * The parameter 'with data' contains the string provided as the first parameter "p" of NotifySmile.
 * See ThreadedApp Script for an example.
 * If NotifySmile is called with "suspend" true, the EventHandler is stopped and will resume as soon as the application receives the "resume" event from Smile.
 * AEInstallThreadedEventHandler also installs an EventHandler for the "resume" event.
 * The AppleScript interface of the resume event must appear in the application dictionary.
 * This event must be registered as in the ThreadedApp sample (see. ThreadedApp.sdef).
 */
OSErr  AEInstallThreadedEventHandler(AEEventClass theAEEventClass, AEEventID theAEEventID, AEEventHandlerUPP handler,
		long handlerRefcon, Boolean isSysHandler);
OSErr NotifySmile(const char* p, Boolean suspend);

#ifdef __cplusplus
}
#endif
#endif

